package com.mhy.rest.controller;

import com.mhy.rest.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {
    @GetMapping("/users")
    public List<User> getUsers(){
        List<User> users = new ArrayList<>();
        users.add(new User(1, "Tom", "123"));
        users.add(new User(2,"哈哈哈","147"));
        return users;
    }

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Integer id){
        User user = new User(id,"Tom", "123");
        return user;
    }

    @PostMapping("/user")
    public boolean addOneUser(@RequestBody User user){
        System.out.println("添加");
        System.out.println(user);
        return true;
    }

    @PutMapping("/user/{id}")
    public boolean updateOneUser(@PathVariable("id") Integer id, @RequestBody User user){
        System.out.println("修改");
        System.out.println(id);
        System.out.println(user);
        return true;
    }

    @DeleteMapping("/user/{id}")
    public boolean deleteUser(@PathVariable("id") Integer id){
        System.out.println("删除");
        System.out.println(id);
        return true;
    }
}
